import java.util.Arrays;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 23735
 * Date: 2023-05-04
 * Time: 9:29
 */

class MyComparator implements Comparator<String> {
//     比较方式变化了
//     比较的方式是, 两个数字结合, 左右顺序变化一下进行比较
//     采取结合后结果更小的方式, 然后将左部的数字放前面
    @Override
    public int compare(String o1, String o2) {
        String ab = o1 + o2;
        String ba = o2 + o1;
        return ab.compareTo(ba);
    }
}

public class Solution {
    public String PrintMinNumber(int [] numbers) {
        String[] arr = new String[numbers.length];
        for (int i = 0; i < numbers.length; i++) {
            arr[i] = String.valueOf(numbers[i]);
        }
        Arrays.sort(arr, new MyComparator());
        // 对结果进行拼接
        StringBuilder result = new StringBuilder();
        for (String s: arr) {
            result.append(s);
        }
        return result.toString();
    }
}
